import { Controller } from 'egg';

export default class collectController extends Controller {

  /**
   * 收货地址列表
   */
  async list() {
    const { query } = this.ctx.validateReq('collect.list');
    const { page, pageSize, ...where } = query;

    const list = await this.ctx.service.wx.collect.index(page, pageSize, where);
    this.ctx.success({
      data: list,
    });
  }

  /**
   * 收藏商品
   */
  async create() {
    const { body } = this.ctx.validateReq('collect.create');

    const data = await this.ctx.service.wx.collect.create(body);

    this.ctx.success({
      data
    });
  }

  async update() {
    const { body } = this.ctx.validateReq('collect.update');

    const result = await this.ctx.service.wx.collect.update(body.id, body);

    this.ctx.success({
      data: {
        id: result.id,
      },
    });
  }
  


  async detail() {
    const { params: { id } } = this.ctx.validateReq('collect.detail');

    const data = await this.ctx.service.wx.collect.detail(id);

    if (data) {
      this.ctx.success({
        data,
        status: 201,
      });
    }
  }


  async destroy() {
    const { params: { id } } = this.ctx.validateReq('collect.destroy');

    const result = await this.ctx.service.wx.collect.destroy(id);

    if (result) {
      this.ctx.success({
        data: {
          id: result.id,
        },
        status: 201,
      });
    }
  }

}
